package com.eqdd.yiqidian.ui;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.eqdd.yiqidian.GuideActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.BGABannerAdapter;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.utils.SPUtil;

public class GuideActivity extends BaseActivity implements ViewPager.OnPageChangeListener, View.OnClickListener {
    private GuideActivityCustom dataBinding;
    private int[] resIds = {R.mipmap.guide1, R.mipmap.guide2,
            R.mipmap.guide3, R.mipmap.guide4, R.mipmap.guide5, R.mipmap.guide6};

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_guide);
    }

    @Override
    public void initData() {
        dataBinding.bannerViewpager.setAdapter(new BGABannerAdapter(this));
        dataBinding.bannerViewpager.setData(resIds);
        dataBinding.bannerViewpager.setOnPageChangeListener(this);

    }

    @Override
    public void setView() {

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int arg0) {
        if (arg0 == resIds.length - 1) {
            dataBinding.btnStart.setVisibility(View.VISIBLE);
            dataBinding.bannerViewpager.setAutoPlayAble(false);
            dataBinding.bannerViewpager.stopAutoPlay();
        } else {
            dataBinding.bannerViewpager.setAutoPlayAble(true);
            dataBinding.bannerViewpager.startAutoPlay();
            dataBinding.btnStart.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_start:
                SPUtil.saveFirst(AppConstent.first_open_app);
                Intent login = new Intent(this, LoginActivity.class);
                startActivity(login);
                finish();
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

}
